package top.gytf.unifiedcall.jsr269.properties;

import cn.hutool.core.io.resource.ClassPathResource;
import cn.hutool.setting.yaml.YamlUtil;
import lombok.AccessLevel;
import lombok.RequiredArgsConstructor;

/**
 * 提供当前处理的响应包的配置信息
 */
@RequiredArgsConstructor(access = AccessLevel.PRIVATE)
public class Jsr269PropertiesHolder {
    private static final String CONFIG_FILE_NAME = "unified-call-jsr269.properties";
    private static final Jsr269PropertiesHolder INSTANCE;

    static {
        Jsr269Properties properties;
        try {
            ClassPathResource configFile = new ClassPathResource(CONFIG_FILE_NAME);
            properties = YamlUtil.load(configFile.getStream(), Jsr269Properties.class);
        } catch (Exception e) {
            properties = new Jsr269Properties();
        }
        INSTANCE = new Jsr269PropertiesHolder(properties);
    }

    public static Jsr269PropertiesHolder getInstance() {
        return INSTANCE;
    }

    private final Jsr269Properties jsr269Properties;

    public Jsr269Properties get() {
        return jsr269Properties;
    }
}
